package org.posta.web.server;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.inject.Injector;

public abstract class InjectableService extends RemoteServiceServlet
{
    private static Logger base_log = LoggerFactory.getLogger(InjectableService.class);
    
    @Override
    public void init(ServletConfig config) throws ServletException
    {
        super.init(config);
        ServletContext context = config.getServletContext();
        
        Injector injector = (Injector) context.getAttribute(Injector.class.getName());
        if (injector == null)
        {
            base_log.error("Guice Injector not found");
            throw new UnavailableException("Guice Injector not found");
        }
        
        injector.injectMembers(this);
    }
}
